//
// Created by ziya on 2021/4/28.
//

#include "CollectedHeap.h"
#include "../memory/genCollectedHeap.h"
#include "../memory/Universe.h"

oop CollectedHeap::obj_allocate(size_t size) {
    HeapWord* obj = common_mem_allocate_init(size);

    return (oop)(obj->value());
}

HeapWord* CollectedHeap::common_mem_allocate_init(size_t size) {
    HeapWord* obj = common_mem_allocate_noinit(size);

    return obj;
}

HeapWord* CollectedHeap::common_mem_allocate_noinit(size_t size) {
    HeapWord* result = NULL;

    //TODO 先尝试从TLAB中分配，后面实现

    // 直接去堆中-新生代分配
    GenCollectedHeap* heap = (GenCollectedHeap *)Universe::heap();

    result = heap->mem_allocate(size);
    if (NULL == result) {
        // 输出OOM信息
    }

    return result;
}
